package Control;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.SystemColor;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JSpinner;
import javax.swing.JTabbedPane;
import javax.swing.SpinnerDateModel;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingConstants;
import javax.swing.SwingWorker;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import Entity.Shop_Catalog;
import Entity.Shop_Order;
import Entity.Shop_Product;
import Form.Shop_Customization_Form;
import Form.Shop_Order_Form;
import Form.Shop_Product_Form;
import Form.Shop_Product_Search_Form;
import Styling.TextBubbleBorder;

public class Shop_Product_Controller {

	private static Shop_Order order;
	private Shop_Product_Form parser;
	private Shop_Product_Search_Form secondaryParser;
	private static Shop_Order_Form thirdParser;
	private ArrayList<Shop_Catalog> catalogList;
	private ArrayList<Shop_Product> productListUnderCat;
	private ArrayList<Shop_Product> searchedProducts;
	private Date collectionDate = null;
	private boolean successCreateOrder = false;
	
	public Shop_Product_Controller(Shop_Product_Search_Form parser){
		
		this.secondaryParser = parser;
		
		//Set order session
		if(order == null)
			this.setOrder(new Shop_Order(CommonControls.generateDefaultType5DigitCode('O')));
		
		search();
		
	}
	
	public void search(){
		secondaryParser.getProducts().removeAll();
		secondaryParser.getProducts().repaint();
		
		String rawKeywords = secondaryParser.getParser().getTxtKeywords().getText();
		Scanner sc = new Scanner(rawKeywords);
		sc.useDelimiter(" ");
		
		final ArrayList<String> keywords = new ArrayList<String> ();
		
		while(sc.hasNext()){
			keywords.add(sc.next());
		}
		SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>(){

			@Override
			protected Void doInBackground() throws Exception {
				searchedProducts = Shop_Product.getSearchProducts(keywords);
				return null;
			}
			
			protected void done(){
				int noRows = 0;
				
				if(searchedProducts.size() / 6 == 0){
					noRows = searchedProducts.size() / 6;
				}
				else{
					noRows = (searchedProducts.size() / 6) + 1;
				}
				
				secondaryParser.getProducts().setPreferredSize(new Dimension(480, noRows * 150));
				for(int i = 0; i < searchedProducts.size(); i++){
					final int tempIndex = i;
					
					final JPanel product = new JPanel();
					product.setPreferredSize(new Dimension(105, 150));
					product.setBackground(Color.decode("#eeeeee"));
					product.setBorder(new TextBubbleBorder(Color.decode("#002640"), 2, 5, 0));
					
					final JLabel img = new JLabel();
					img.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(searchedProducts.get(tempIndex).getFrontImageUrl()).getScaledInstance(80, 100, Image.SCALE_DEFAULT)));
					img.setPreferredSize(new Dimension(95, 110));
					img.setHorizontalAlignment(JLabel.CENTER);
					if(searchedProducts.get(tempIndex).getProductStatus().getStatusCode().equals("AVA")){
						img.addMouseListener(new MouseListener(){
	
							@Override
							public void mouseClicked(MouseEvent arg0) {
								new Shop_Customization_Form(getSecondaryParser().getParser(), getSecondaryParser(), false, searchedProducts.get(tempIndex));
							}
	
							@Override
							public void mouseEntered(MouseEvent arg0) {
								img.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(searchedProducts.get(tempIndex).getBackImageUrl()).getScaledInstance(80, 100, Image.SCALE_DEFAULT)));
								product.setBackground(Color.decode("#002640"));
							}
	
							@Override
							public void mouseExited(MouseEvent arg0) {
								img.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(searchedProducts.get(tempIndex).getFrontImageUrl()).getScaledInstance(80, 100, Image.SCALE_DEFAULT)));
								product.setBackground(Color.decode("#eeeeee"));
							}
	
							@Override
							public void mousePressed(MouseEvent arg0) {
								// TODO Auto-generated method stub
								
							}
	
							@Override
							public void mouseReleased(MouseEvent arg0) {
								// TODO Auto-generated method stub
								
							}
							
						});
					}
					product.add(img);
					
					if(searchedProducts.get(tempIndex).getProductStatus().getStatusCode().equals("UVA")){
						JLabel unavailable = new JLabel("Unavailable");
						unavailable.setFont(new Font("Segoe UI", Font.BOLD, 12));
						unavailable.setForeground(Color.RED);
						product.add(unavailable);
					}
					else{
						JLabel available = new JLabel("Available");
						available.setFont(new Font("Segoe UI", Font.BOLD, 12));
						available.setForeground(Color.decode("#37ce26"));
						product.add(available);
					}

					secondaryParser.getProducts().add(product);
				}
				secondaryParser.getLblHeader().setText("Searched a total of " + keywords.size() + " keywords : " + searchedProducts.size() + " results returned");
				secondaryParser.getParser().closeProgressBar();
			}
			
		};
		secondaryParser.getParser().getProgressBar();
		worker.execute();
		
	}
	
	public Shop_Product_Controller(final Shop_Product_Form parser){
		
		this.parser = parser;
		
		//Set order session
		if(order == null)
			this.setOrder(new Shop_Order(CommonControls.generateDefaultType5DigitCode('O')));
		
		SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>(){

			@Override
			protected Void doInBackground() throws Exception {
				catalogList = Shop_Catalog.retrieveAllCatalogs();
				return null;
			}
			
			protected void done(){
				getParser().getCatalogs().setPreferredSize(new Dimension(140, catalogList.size() * 80));
			
				for(int i = 0; i < catalogList.size(); i++){
					final int tempIndex = i;
					
					JPanel catalog = new JPanel();
					final JLabel catalogName = new JLabel(catalogList.get(i).getName());
					final JLabel catalogId = new JLabel("id: " + catalogList.get(i).getId());
					
					MouseListener viewCategoryToggle = new MouseListener(){
	
						@Override
						public void mouseClicked(MouseEvent e) {
							getParser().getLblCatalogname().setText(catalogList.get(tempIndex).getName());
							SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>(){

								@Override
								protected Void doInBackground(){
									productListUnderCat = Shop_Product.getProductsUnderCat(catalogList.get(tempIndex).getId());
									return null;
								}
								
								protected void done(){
									getParser().getProducts().removeAll();
									getParser().repaint();
									
									int numRows = 0;
									
									if(productListUnderCat.size() / 4 == 0)
										numRows = productListUnderCat.size() / 4;
									else
										numRows = (productListUnderCat.size() / 4) + 1;
									
									getParser().getProducts().setPreferredSize(new Dimension(400, numRows * 150));
									
									for(int i = 0; i < productListUnderCat.size(); i++){
										final int tempIndex = i;
										
										final JPanel product = new JPanel();
										product.setPreferredSize(new Dimension(95, 150));
										product.setBackground(Color.decode("#eeeeee"));
										product.setBorder(new TextBubbleBorder(Color.decode("#002640"), 2, 5, 0));
										
										final JLabel img = new JLabel();
										img.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(productListUnderCat.get(tempIndex).getFrontImageUrl()).getScaledInstance(80, 100, Image.SCALE_DEFAULT)));
										img.setPreferredSize(new Dimension(85, 110));
										img.setHorizontalAlignment(JLabel.CENTER);
										if(productListUnderCat.get(tempIndex).getProductStatus().getStatusCode().equals("AVA")){
											img.addMouseListener(new MouseListener(){
						
												@Override
												public void mouseClicked(MouseEvent arg0) {
													new Shop_Customization_Form(getParser().getParser(), getParser(), false, productListUnderCat.get(tempIndex));
												}
						
												@Override
												public void mouseEntered(MouseEvent arg0) {
													img.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(productListUnderCat.get(tempIndex).getBackImageUrl()).getScaledInstance(80, 100, Image.SCALE_DEFAULT)));
													product.setBackground(Color.decode("#002640"));
												}
						
												@Override
												public void mouseExited(MouseEvent arg0) {
													img.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(productListUnderCat.get(tempIndex).getFrontImageUrl()).getScaledInstance(80, 100, Image.SCALE_DEFAULT)));
													product.setBackground(Color.decode("#eeeeee"));
												}
						
												@Override
												public void mousePressed(MouseEvent arg0) {
													// TODO Auto-generated method stub
													
												}
						
												@Override
												public void mouseReleased(MouseEvent arg0) {
													// TODO Auto-generated method stub
													
												}
												
											});
										}
										product.add(img);
										
										if(productListUnderCat.get(tempIndex).getProductStatus().getStatusCode().equals("UVA")){
											JLabel unavailable = new JLabel("Unavailable");
											unavailable.setFont(new Font("Segoe UI", Font.BOLD, 10));
											unavailable.setForeground(Color.RED);
											product.add(unavailable);
										}
										else{
											JLabel available = new JLabel("Available");
											available.setFont(new Font("Segoe UI", Font.BOLD, 10));
											available.setForeground(Color.decode("#37ce26"));
											product.add(available);
										}

										parser.getProducts().add(product);
									}
									parser.getParser().closeProgressBar();
								}
							};
							parser.getParser().getProgressBar();
							worker.execute();
							
						}
	
						@Override
						public void mouseEntered(MouseEvent e) {
							catalogName.setBackground(Color.decode("#002640"));
							catalogId.setBackground(Color.decode("#002640"));
							catalogName.setForeground(Color.WHITE);
							catalogId.setForeground(Color.WHITE);
						}
	
						@Override
						public void mouseExited(MouseEvent e) {
							catalogName.setBackground(Color.decode("#eeeeee"));
							catalogId.setBackground(Color.decode("#eeeeee"));
							catalogName.setForeground(Color.BLACK);
							catalogId.setForeground(Color.BLACK);
						}
	
						@Override
						public void mousePressed(MouseEvent e) {
							// TODO Auto-generated method stub
							
						}
	
						@Override
						public void mouseReleased(MouseEvent e) {
							// TODO Auto-generated method stub
							
						}
						
					};
					
					catalog.setLayout(new GridLayout(0, 1));
					catalog.setPreferredSize(new Dimension(140, 80));
					catalog.setBorder(new TextBubbleBorder(Color.decode("#002640"), 2, 5, 0));
					catalog.addMouseListener(viewCategoryToggle);
	
					catalogName.setHorizontalAlignment(SwingConstants.CENTER);
					catalogName.setVerticalAlignment(SwingConstants.BOTTOM);
					catalogName.setForeground(Color.BLACK);
					catalogName.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 18));
					catalogName.setOpaque(true);
					catalogName.setBackground(Color.decode("#eeeeee"));
					catalogName.addMouseListener(viewCategoryToggle);
					catalog.add(catalogName);
					
					catalogId.setHorizontalAlignment(SwingConstants.CENTER);
					catalogId.setVerticalAlignment(SwingConstants.TOP);
					catalogId.setForeground(Color.BLACK);
					catalogId.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
					catalogId.setOpaque(true);
					catalogId.setBackground(Color.decode("#eeeeee"));
					catalogId.addMouseListener(viewCategoryToggle);
					catalog.add(catalogId);
	
					getParser().getCatalogs().add(catalog);
				};
				parser.getParser().closeProgressBar();
			}
			
		};
		parser.getParser().getProgressBar();
		worker.execute();
	}
	
	public Shop_Product_Controller(Shop_Order_Form thirdParser){
		setThirdParser(thirdParser);

		//Set order session
		if(order == null)
			this.setOrder(new Shop_Order(CommonControls.generateDefaultType5DigitCode('O')));
		
		viewCart();
	}
	
	public void viewCart(){
		if(thirdParser != null){
			thirdParser.getProducts().removeAll();
			thirdParser.getProducts().repaint();
			thirdParser.getProducts().setPreferredSize(new Dimension(500, order.getCustomizations().size() * 140));
			for(int i = 0; i < order.getCustomizations().size(); i++){
				
				final int tempIndex = i;

				Color background;
				final Color foreground;
				FlowLayout layout;
				
				if(i % 2 == 0){
					background = Color.LIGHT_GRAY;
					foreground = Color.DARK_GRAY;
				}
				else{
					background = Color.DARK_GRAY;
					foreground = Color.LIGHT_GRAY;
				}
				
				JPanel orderHolder = new JPanel();
				orderHolder.setPreferredSize(new Dimension(500, 140));
				orderHolder.setBackground(background);
				layout = (FlowLayout)orderHolder.getLayout();
				layout.setAlignment(FlowLayout.LEFT);
				
				JPanel details = new JPanel();
				details.setPreferredSize(new Dimension(100, 130));
				details.setOpaque(false);
				details.setBorder(BorderFactory.createLineBorder(background));
				
				JLabel custId = new JLabel();
				custId.setText(order.getCustomizations().get(i).getCustId());
				custId.setForeground(foreground);
				custId.setFont(new Font("Segoe UI", Font.BOLD, 20));
				custId.setPreferredSize(new Dimension(90, 30));
				custId.setVerticalAlignment(JLabel.TOP);
				details.add(custId);
				
				final JLabel img = new JLabel();
				img.setOpaque(true);
				img.setBackground(Color.GRAY);
				img.setPreferredSize(new Dimension(70, 90));
				img.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(order.getCustomizations().get(i).getFrontCustUrl()).getScaledInstance(70, 90, Image.SCALE_DEFAULT)));
				img.addMouseListener(new MouseListener(){

					@Override
					public void mouseClicked(MouseEvent arg0) {
						JDialog image = new JDialog(thirdParser.getParser(), true);
						JTabbedPane enlarged = new JTabbedPane();
						
						JLabel enlargedFront = new JLabel();
						enlargedFront.setPreferredSize(new Dimension(300, 400));
						enlargedFront.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(order.getCustomizations().get(tempIndex).getFrontCustUrl()).getScaledInstance(300, 400, Image.SCALE_DEFAULT)));
						enlarged.addTab("Front", enlargedFront);
						
						JLabel enlargedBack = new JLabel();
						enlargedBack.setPreferredSize(new Dimension(300, 400));
						enlargedBack.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(order.getCustomizations().get(tempIndex).getBackCustUrl()).getScaledInstance(300, 400, Image.SCALE_DEFAULT)));
						enlarged.addTab("Back", enlargedBack);
						image.add(enlarged);
						
						image.pack();
						image.setLocationRelativeTo(thirdParser.getParser());
						image.setVisible(true);
					}

					@Override
					public void mouseEntered(MouseEvent arg0) {
						img.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(order.getCustomizations().get(tempIndex).getBackCustUrl()).getScaledInstance(70, 90, Image.SCALE_DEFAULT)));

					}

					@Override
					public void mouseExited(MouseEvent arg0) {
						img.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(order.getCustomizations().get(tempIndex).getFrontCustUrl()).getScaledInstance(70, 90, Image.SCALE_DEFAULT)));

					}

					@Override
					public void mousePressed(MouseEvent arg0) {
						// TODO Auto-generated method stub
						
					}

					@Override
					public void mouseReleased(MouseEvent arg0) {
						// TODO Auto-generated method stub
						
					}
					
				});
				details.add(img);
				
				orderHolder.add(details);
				
				JPanel information = new JPanel();
				information.setPreferredSize(new Dimension(390, 130));
				information.setOpaque(false);
				information.setBorder(BorderFactory.createLineBorder(background));
				layout = (FlowLayout)information.getLayout();
				layout.setAlignment(FlowLayout.LEFT);
				
				JLabel text;
				JSeparator split;
				
				text = new JLabel(order.getCustomizations().get(i).getProduct().getName());
				text.setFont(new Font("Segoe UI", Font.BOLD, 20));
				text.setForeground(foreground);
				information.add(text);
				
				final JLabel deleteBtn = new JLabel("Delete");
				deleteBtn.setPreferredSize(new Dimension(80, 20));
				deleteBtn.setFont(new Font("Segoe UI", Font.PLAIN, 12));
				deleteBtn.setVerticalAlignment(JLabel.CENTER);
				deleteBtn.setHorizontalAlignment(JLabel.CENTER);
				deleteBtn.setBorder(BorderFactory.createLineBorder(SystemColor.inactiveCaptionBorder, 3));
				deleteBtn.setForeground(Color.DARK_GRAY);
				deleteBtn.setOpaque(true);
				deleteBtn.setBackground(SystemColor.inactiveCaptionBorder);
				
				final Shop_Product_Controller control = this;
				deleteBtn.addMouseListener(new MouseListener(){

					@Override
					public void mouseClicked(MouseEvent arg0) {
						order.getCustomizations().remove(order.getCustomizations().indexOf(order.getCustomizations().get(tempIndex)));
						viewCart();
						control.getThirdParser().repaint();
						control.getThirdParser().revalidate();
					}

					@Override
					public void mouseEntered(MouseEvent arg0) {
						deleteBtn.setForeground(Color.WHITE);
					}

					@Override
					public void mouseExited(MouseEvent arg0) {
						deleteBtn.setForeground(foreground);
					}

					@Override
					public void mousePressed(MouseEvent arg0) {
						// TODO Auto-generated method stub
						
					}

					@Override
					public void mouseReleased(MouseEvent arg0) {
						// TODO Auto-generated method stub
						
					}
					
				});
				information.add(deleteBtn);
				
				split = new JSeparator();
				split.setPreferredSize(new Dimension(380, 10));
				information.add(split);
				
				text = new JLabel("Quantity: ");
				text.setForeground(foreground);
				text.setFont(new Font("Segoe UI", Font.BOLD, 13));
				information.add(text);
				
				final JLabel price = new JLabel(Double.toString(order.getCustomizations().get(i).getProduct().getUnitPrice() * order.getCustomizations().get(i).getQuantity()));
				
				final JSpinner quantity = new JSpinner();
				quantity.setFont(new Font("Segoe UI", Font.BOLD, 13));
				quantity.setModel(new SpinnerNumberModel(order.getCustomizations().get(i).getQuantity(), 1, 10, 1));
				quantity.setPreferredSize(new Dimension(40, 20));
				quantity.addChangeListener(new ChangeListener(){

					@Override
					public void stateChanged(ChangeEvent arg0) {
						order.getCustomizations().get(tempIndex).setQuantity((Integer)quantity.getValue());
						price.setText(Double.toString(order.getCustomizations().get(tempIndex).getProduct().getUnitPrice() * order.getCustomizations().get(tempIndex).getQuantity()));
						calculateTotal();
					}
					
				});
				information.add(quantity);
				
				split = new JSeparator();
				split.setPreferredSize(new Dimension(380, 0));
				information.add(split);
				
				text = new JLabel("Price: $");
				text.setForeground(foreground);
				text.setFont(new Font("Segoe UI", Font.BOLD, 17));
				information.add(text);
				
				price.setForeground(foreground);
				price.setFont(new Font("Segoe UI", Font.BOLD, 17));
				information.add(price);
				
				orderHolder.add(information);
				
				thirdParser.getProducts().add(orderHolder);
			}
			calculateTotal();
			thirdParser.getProducts().repaint();
			thirdParser.getProducts().revalidate();
		}
	}
	
	public void calculateTotal(){
		double total = 0;
		for(int i = 0; i < order.getCustomizations().size(); i++){
			total += order.getCustomizations().get(i).getQuantity() * order.getCustomizations().get(i).getProduct().getUnitPrice();
		}
		thirdParser.getTotalPrice().setText(Double.toString(total));
		if(total == 0){
			thirdParser.getBtnCheckout().setEnabled(false);
		}
		else{
			thirdParser.getBtnCheckout().setEnabled(true);
		}
	}
	
	public void checkOut(){
		final JDialog getCollectionDate = new JDialog(thirdParser.getParser(), true);
		getCollectionDate.setTitle("Select Collection Date");
		JPanel content = (JPanel) getCollectionDate.getContentPane();
		content.setLayout(new GridLayout(0, 1));
		JPanel date = new JPanel();
		final JSpinner datePicker = new JSpinner();
		int totalQuantity = 0;
		for(int i = 0; i < order.getCustomizations().size(); i++){
			totalQuantity += order.getCustomizations().get(i).getQuantity();
		}
		int noWeeks = 1;
		if(totalQuantity / 10 > 0){
			noWeeks = totalQuantity / 10;
		}
		Date minDate = CommonControls.addDayToDate(CommonControls.getCurrentDate(), noWeeks * 7);
		datePicker.setModel(new SpinnerDateModel(CommonControls.addDayToDate(minDate, 1), minDate, CommonControls.addMonthToDate(minDate, 2), Calendar.DAY_OF_YEAR));
		datePicker.setPreferredSize(new Dimension(110, 20));
		date.add(datePicker);
		JButton confirm = new JButton("Confirm");
		confirm.addMouseListener(new MouseListener(){

			@Override
			public void mouseClicked(MouseEvent arg0) {
				getCollectionDate.setVisible(false);
				setCollectionDate((Date)datePicker.getValue());
				order.setCustomerNric(CommonControls.getUser().getNric());
				order.setOrderDate(CommonControls.getCurrentDate());
				order.setCollectDate(collectionDate);
				order.setTotalPrice(Double.parseDouble(thirdParser.getTotalPrice().getText()));
				SwingWorker <Void, Void> worker = new SwingWorker<Void, Void>(){
					
					@Override
					protected Void doInBackground() throws Exception {
						successCreateOrder = order.createOrder();
						for(int i = 0; i < order.getCustomizations().size(); i++){
							if(!successCreateOrder)
								break;
							successCreateOrder = order.getCustomizations().get(i).createCustomization();
						}
						return null;
					}
					
					protected void done(){
						thirdParser.getParser().closeProgressBar();
						if(successCreateOrder){
							thirdParser.getProducts().removeAll();
							thirdParser.getProducts().repaint();
							order = new Shop_Order(CommonControls.generateDefaultType5DigitCode('O'));
							thirdParser.getTotalPrice().setText("0.0");
							successCreateOrder = false;
							setCollectionDate(null);
							thirdParser.getParser().displayMessage(true, "Order Number: " + order.getOrderId() + "\nOrder has been made, you may check your order status anytime in your order history.\nThank you for your support.");
							
						}
						else{
							thirdParser.getParser().displayMessage(false, "Sorry,\nwe have encountered some problems processing your order. Please try again after awhile.\nWe apologise for any inconveniences caused.");
						}
					}
					
				};
				thirdParser.getParser().getProgressBar();
				worker.execute();
			}

			@Override
			public void mouseEntered(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseExited(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mousePressed(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseReleased(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
		});
		date.add(confirm);
		content.add(date);
		JPanel note = new JPanel();
		note.setPreferredSize(new Dimension(400, 40));
		FlowLayout layout = (FlowLayout)note.getLayout();
		layout.setAlignment(FlowLayout.LEFT);
		SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
		JLabel earliest = new JLabel("Earliest collection date: " + sdf.format(minDate) + " (Min. " + (noWeeks * 7) + " working days)");
		note.add(earliest);
		JLabel instructions = new JLabel("*Note: Every batch of 10 requries tentatively up to 7 working days to complete.");
		note.add(instructions);
		content.add(note);
		getCollectionDate.pack();
		getCollectionDate.setLocationRelativeTo(thirdParser.getParser());
		getCollectionDate.setVisible(true);
	}

	/**
	 * @return the order
	 */
	public Shop_Order getOrder() {
		return order;
	}

	/**
	 * @param order the order to set
	 */
	public void setOrder(Shop_Order order) {
		Shop_Product_Controller.order = order;
	}

	public Date getCollectionDate() {
		return collectionDate;
	}

	public void setCollectionDate(Date collectionDate) {
		this.collectionDate = collectionDate;
	}

	public Shop_Product_Form getParser() {
		return parser;
	}

	public void setParser(Shop_Product_Form parser) {
		this.parser = parser;
	}

	public Shop_Product_Search_Form getSecondaryParser() {
		return secondaryParser;
	}

	public void setSecondaryParser(Shop_Product_Search_Form secondaryParser) {
		this.secondaryParser = secondaryParser;
	}

	public Shop_Order_Form getThirdParser() {
		return thirdParser;
	}

	public void setThirdParser(Shop_Order_Form thirdParser) {
		Shop_Product_Controller.thirdParser = thirdParser;
	}
	
}
